<template>
	<view class="update-payment-password-layout">
		<view class="update-password-form">

			<xh-input :showTitle="true" title="原密码" minWidth="180rpx" placeholder="请输入原密码" padding="30rpx" v-model="formParams.oldPassword" :isEye="true" :password="true" keyboardType="number" :maxCount="6"></xh-input>
			<xh-input :showTitle="true" title="新密码" minWidth="180rpx" placeholder="请输入6位数字密码" padding="30rpx" v-model="formParams.password" :isEye="true" :password="true" keyboardType="number" :maxCount="6"></xh-input>
			<xh-input :showTitle="true" title="确认新密码" minWidth="180rpx" placeholder="再次输入新密码" padding="30rpx" v-model="formParams.surePassword" :isEye="true" :password="true" keyboardType="number" :maxCount="6"></xh-input>
			
		</view>
		<view class="forget-box">
			<text @tap="showSetPassword">忘记密码？</text>
		</view>
		<view class="submit-btn" :style="{marginTop:'50rpx'}" @tap="submit">确认修改</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { updatePayPassword } from '@/common/api/api.js'
	const formParams = ref({
		oldPassword:'',
		password:'',
		surePassword:''
	})
	//设置密码
	const showSetPassword = ()=>{
		uni.navigateTo({
			url:'/pages/my/setting/set-payment-password/set-payment-password'
		})
	}
	// 提交
	const submit = async ()=>{
		if(uni.$uv.test.empty(formParams.value.oldPassword)) {
			uni.$utils.showToast('请输入原支付密码')
			return
		}
		else if(uni.$uv.test.empty(formParams.value.password)) {
			uni.$utils.showToast('请输入6位数字支付密码')
			return
		}
		else if(!uni.$utils.checkPayPassword(formParams.value.password)) {
			uni.$utils.showToast('密码必须是6位数字')
			return
		}
		else if(uni.$uv.test.empty(formParams.value.surePassword)) {
			uni.$utils.showToast('请再次输入新密码')
			return
		}
		else if(formParams.value.password != formParams.value.surePassword) {
			uni.$utils.showToast('两次输入的密码不一致')
			return
		}
		let params = {}
		const oldPwdRes = uni.$utils.passwordEncrypt(formParams.value.oldPassword)
		const pwdRes = uni.$utils.passwordEncrypt(formParams.value.password)
		params.password = oldPwdRes
		params.newPassword = pwdRes
		params.confirmPassword = pwdRes
		await updatePayPassword(params)
		uni.$utils.showToast('支付密码修改成功')
		uni.navigateBack()
	}
</script>

<style lang="scss" scoped>
	.update-payment-password-layout {
		padding-top: 1px;
		.update-password-form {
			background-color: #ffffff;
			.password-title{
				width: 200rpx;
			}
		}
		.forget-box{
			display: flex;
			align-items: center;
			justify-content: flex-end;
			padding: 20rpx;
			color: $xh-theme-color;
			font-size: 26rpx;
		}
	}
</style>